package com.fwj.common.web;

import com.alibaba.fastjson.JSONObject;
import com.fwj.common.api.CodeService;
import com.fwj.core.common.annotation.LoginUser;
import com.fwj.core.common.model.ResponseDTO;
import com.fwj.core.common.model.ResponseEnum;
import com.fwj.user.entity.user.UserBaseInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: fwj
 * @Data: 2022/4/25 17:58
 * @Version 1.0
 * @Description:
 */

@RestController
@RequestMapping("/code")
public class CodeController {

    //添加日志工厂
    private static final Logger LOGGER = LoggerFactory.getLogger(CodeController.class);

    @Autowired
    private CodeService codeService;

    @PostMapping("getCodeByType")
    public ResponseDTO getCodeByType(@RequestBody JSONObject jsonObject, @LoginUser UserBaseInfo userBaseInfo) {
        ResponseDTO responseDTO = new ResponseDTO();
        try{
            return codeService.getCodeByType(jsonObject);
        } catch (Exception e){
            LOGGER.error(e.toString());
            e.printStackTrace();
            return responseDTO.fail(ResponseEnum.SERVER_ERROR);
        }
    }


}
